﻿using System;
using System.Collections.Generic;
using System.Linq;
using Apps.Models;
using Apps.Common;
using Microsoft.Practices.Unity;
using System.Transactions;
using Apps.BLL.Core;
using Apps.Locale;
using LinqToExcel;
using System.IO;
using System.Text;
using System.Linq.Expressions;
using Apps.IDAL.PL;
using Apps.Models.PL;
using Apps.IBLL.PL;
namespace Apps.BLL.PL
{
    public partial class PL_RC_PLANSBLL
    {

        public virtual List<PL_RC_PLANSModel> GetList(ref GridPager pager, string queryStr, string sDate, string eDate)
        {

            using (DBContainer db = new DBContainer())
            {
                IQueryable<PL_RC_PLANS> queryData = null;

                var whereLambda = PredicateBuilder.True<PL_RC_PLANS>();

                if (string.IsNullOrWhiteSpace(sDate))
                {
                    sDate = DateTime.Now.AddYears(-30).ToString("yyyy-MM-dd");
                }
                if (string.IsNullOrWhiteSpace(eDate))
                {
                    eDate = DateTime.Now.AddYears(30).ToString("yyyy-MM-dd");
                }
                DateTime dt1 = Convert.ToDateTime(sDate + " 00:00:00");
                DateTime dt2 = Convert.ToDateTime(eDate + " 23:59:59");
                whereLambda = whereLambda.And(p => p.PLAN_DATE >= dt1 && p.PLAN_DATE <= dt2);
                queryData = db.PL_RC_PLANS.Where(whereLambda.Compile()).AsQueryable();


                pager.totalRows = queryData.Count();
                //排序
                queryData = LinqHelper.SortingAndPaging(queryData, pager.sort, pager.order, pager.page, pager.rows);
                return CreateModelList(ref queryData);
            }
        }
    }
}
